home *** CD-ROM | disk | FTP | other *** search
/ MacWarehouse Macintosh Games / MacWarehouse Macintosh Games.iso / AMBER demo / ROXY / ROXY.dxr / 00009_sound wranglers.ls < prev    next >
Encoding:
Text File  |  1996-10-18  |  8.5 KB  |  257 lines

  1. on assignSound whichSound, volumeDesired
  2.   global oStoryteller, oPuppeteer, gSoundPath, gAmberPath, gHDsounds, gSoundPath2
  3.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  4.   set soundBank to getProp(the lsForegroundData of oPuppeteer, #soundBank)
  5.   set freeChannel to #none
  6.   repeat with i = 1 to count(soundChannels)
  7.     set thisChannel to getAt(soundChannels, i)
  8.     if getProp(thisChannel, #sndType) = #none then
  9.       set freeChannel to i
  10.       exit repeat
  11.     end if
  12.   end repeat
  13.   if freeChannel = #none then
  14.     repeat with i = 1 to count(soundChannels)
  15.       set thisChannel to getAt(soundChannels, i)
  16.       if getProp(thisChannel, #sndType) = #effect then
  17.         if soundBusy(i) = 0 then
  18.           set freeChannel to i
  19.           exit repeat
  20.         end if
  21.       end if
  22.     end repeat
  23.   end if
  24.   if freeChannel <> #none then
  25.     if not integerp(volumeDesired) then
  26.       set volumeDesired to 255
  27.     end if
  28.     set volumeTweaks to getaProp(the lsForegroundData of oPuppeteer, #soundVolTweaks)
  29.     if listp(volumeTweaks) then
  30.       set volAdjust to getaProp(volumeTweaks, whichSound)
  31.       if not voidp(volAdjust) then
  32.         set volumeDesired to volumeDesired * volAdjust
  33.       end if
  34.     else
  35.       alert("Sorry, I couldn't find the #soundVolTweaks list in the foreground-data.. here's what I got:")
  36.       put volumeTweaks
  37.     end if
  38.     set the volume of sound freeChannel to volumeDesired
  39.     set soundCast to getProp(soundBank, whichSound)
  40.     if voidp(soundCast) then
  41.       return #badSound
  42.     end if
  43.     if listp(soundCast) then
  44.       set soundCast to getAt(soundCast, random(count(soundCast)))
  45.     end if
  46.     if integerp(soundCast) then
  47.       puppetSound(freeChannel, soundCast)
  48.     end if
  49.     if stringp(soundCast) then
  50.       if getPos(gHDsounds, soundCast) = 0 then
  51.         sound playFile freeChannel, gSoundPath2 & soundCast
  52.       else
  53.         sound playFile freeChannel, gSoundPath & soundCast
  54.       end if
  55.     end if
  56.   end if
  57.   return freeChannel
  58. end
  59.  
  60. on setLoop whichSound, volumeDesired
  61.   global oStoryteller, oPuppeteer
  62.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  63.   if voidp(volumeDesired) then
  64.     set volumeDesired to 255
  65.   end if
  66.   set foundIt to 0
  67.   repeat with i = 1 to count(soundChannels)
  68.     set channelData to getAt(soundChannels, i)
  69.     if getProp(channelData, #sndName) = whichSound then
  70.       set volumeTweaks to getaProp(the lsForegroundData of oPuppeteer, #soundVolTweaks)
  71.       if listp(volumeTweaks) then
  72.         set volAdjust to getaProp(volumeTweaks, whichSound)
  73.         if not voidp(volAdjust) then
  74.           set volumeDesired to volumeDesired * volAdjust
  75.         end if
  76.       else
  77.         alert("Sorry, I couldn't find the #soundVolTweaks list in the foreground-data.. here's what I got:")
  78.         put volumeTweaks
  79.       end if
  80.       setProp(channelData, #volume, volumeDesired)
  81.       set the volume of sound getPropAt(soundChannels, i) to getProp(channelData, #volume)
  82.       set foundIt to 1
  83.     end if
  84.   end repeat
  85.   if foundIt = 0 then
  86.     set foundChannel to assignSound(whichSound, volumeDesired)
  87.     if foundChannel = #none then
  88.       put "setLoop(" & whichSound & "): Sorry, there are no free sound channels at this time."
  89.       reportSounds()
  90.       exit
  91.     end if
  92.     if foundChannel = #badSound then
  93.       beep()
  94.       put "Sorry, there's no such sound as #" & whichSound
  95.       exit
  96.     end if
  97.     set channelData to getProp(soundChannels, foundChannel)
  98.     setProp(channelData, #sndType, #loop)
  99.     setProp(channelData, #sndName, whichSound)
  100.     setProp(channelData, #volume, volumeDesired)
  101.   end if
  102. end
  103.  
  104. on endLoop whichSound
  105.   global oStoryteller
  106.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  107.   repeat with i = 1 to count(soundChannels)
  108.     set channelData to getAt(soundChannels, i)
  109.     if getProp(channelData, #sndName) = whichSound then
  110.       set theChannel to getPropAt(soundChannels, i)
  111.       setProp(soundChannels, theChannel, [#sndType: #none, #sndName: #none, #volume: 0])
  112.       set the volume of sound theChannel to 0
  113.       puppetSound(theChannel, 0)
  114.       sound stop theChannel
  115.       exit repeat
  116.     end if
  117.   end repeat
  118. end
  119.  
  120. on soundEffect whichSound, volumeDesired
  121.   global oStoryteller
  122.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  123.   if voidp(volumeDesired) then
  124.     set volumeDesired to 255
  125.   end if
  126.   set foundChannel to assignSound(whichSound, volumeDesired)
  127.   if foundChannel = #none then
  128.     put "soundEffect(" & whichSound & "): Sorry, there are no free sound channels at this time."
  129.     reportSounds()
  130.     exit
  131.   else
  132.     set channelData to getProp(soundChannels, foundChannel)
  133.     setProp(channelData, #sndType, #effect)
  134.     setProp(channelData, #sndName, whichSound)
  135.     setProp(channelData, #volume, volumeDesired)
  136.   end if
  137. end
  138.  
  139. on suspendSounds fadeSwitch
  140.   global oStoryteller, gSoundsSuspended
  141.   set gSoundsSuspended to 1
  142.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  143.   if fadeSwitch = #fadeOut then
  144.     repeat with fadeFactor in [0.90000000000000002, 0.75, 0.5, 0.25, 0.10000000000000001, 0.05]
  145.       repeat with i = 1 to count(soundChannels)
  146.         set theChannel to getPropAt(soundChannels, i)
  147.         set the volume of sound theChannel to getProp(getProp(soundChannels, theChannel), #volume) * fadeFactor
  148.       end repeat
  149.       set the volume of sound 5 to the volume of sound 5 * fadeFactor
  150.       wait(3)
  151.       updateStage()
  152.     end repeat
  153.   end if
  154.   repeat with i = 1 to count(soundChannels)
  155.     set theChannel to getPropAt(soundChannels, i)
  156.     set the volume of sound theChannel to 0
  157.     puppetSound(theChannel, 0)
  158.     sound stop theChannel
  159.   end repeat
  160.   set the volume of sound 5 to 0
  161.   puppetSound(5, 0)
  162.   sound stop 5
  163.   updateStage()
  164. end
  165.  
  166. on suspendCallsTest
  167.   suspendSounds(#fadeOut)
  168.   wait(360)
  169.   restoreSounds(#fadeIn)
  170. end
  171.  
  172. on restoreSounds fadeSwitch
  173.   global oStoryteller, oPuppeteer, gSoundsSuspended
  174.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  175.   set soundBank to getProp(the lsForegroundData of oPuppeteer, #soundBank)
  176.   repeat with i = 1 to count(soundChannels)
  177.     set theChannel to getPropAt(soundChannels, i)
  178.     set channelData to getAt(soundChannels, i)
  179.     set mySndType to getProp(channelData, #sndType)
  180.     if mySndType = #none then
  181.       next repeat
  182.       next repeat
  183.     end if
  184.     if mySndType = #effect then
  185.       setProp(soundChannels, theChannel, [#sndType: #none, #sndName: #none, #volume: 0])
  186.       next repeat
  187.     end if
  188.     set theCast to getProp(soundBank, getProp(channelData, #sndName))
  189.     puppetSound(theChannel, theCast)
  190.   end repeat
  191.   if fadeSwitch = #fadeIn then
  192.     set lsFadeFactors to [0.05, 0.10000000000000001, 0.25, 0.5, 0.75, 0.90000000000000002, 1.0]
  193.   else
  194.     set lsFadeFactors to [1.0]
  195.   end if
  196.   repeat with fadeFactor in lsFadeFactors
  197.     repeat with i = 1 to count(soundChannels)
  198.       set theChannel to getPropAt(soundChannels, i)
  199.       set channelData to getAt(soundChannels, i)
  200.       if getProp(channelData, #sndType) = #loop then
  201.         set the volume of sound theChannel to getProp(channelData, #volume) * fadeFactor
  202.       end if
  203.     end repeat
  204.     wait(3)
  205.     updateStage()
  206.   end repeat
  207.   set gSoundsSuspended to 0
  208. end
  209.  
  210. on reportSounds
  211.   global oStoryteller
  212.   set soundChannels to getProp(the lsStateData of oStoryteller, #soundChannels)
  213.   put "‚Ä¢‚Ä¢‚Ä¢ Sound report ‚Ä¢‚Ä¢‚Ä¢"
  214.   repeat with i = 1 to count(soundChannels)
  215.     put " > Sound " & getPropAt(soundChannels, i) & ": " & getAt(soundChannels, i)
  216.   end repeat
  217.   put "‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢‚Ä¢"
  218. end
  219.  
  220. on fadeOutTransit
  221.   set STIME to the ticks
  222.   put "fadeOutTransit() starting.."
  223.   repeat with fadeFactor = 30.0 down to 0.0
  224.     repeat with i = 1 to 4
  225.       set the volume of sound i to float(the volume of sound i) * (fadeFactor / 30.0)
  226.       updateStage()
  227.     end repeat
  228.     wait(4)
  229.     updateStage()
  230.   end repeat
  231.   put "fadeOutTransit() done at " & the ticks - STIME
  232. end
  233.  
  234. on transitToEdwin
  235.   global oStorytelller, oPuppeteer, gOriginPoint
  236.   cursorOff()
  237.   setState(oStoryteller, #AMBERVISION, #off)
  238.   suspendSounds(#fadeOut)
  239.   set the loc of sprite 39 to point(320, -500) + gOriginPoint
  240.   setState(oStoryteller, #showMontage, 1)
  241.   updateDisplay(oPuppeteer)
  242.   soundEffect(#toEdwin)
  243.   pushVideo()
  244.   wait(#videoStop)
  245.   setState(oStoryteller, #showMontage, 2)
  246.   killVideo()
  247.   updateDisplay(oPuppeteer)
  248.   pushVideo()
  249.   wait(#videoStop)
  250.   killVideo()
  251.   setState(oStoryteller, #showMontage, 3)
  252.   setTransition(oPuppeteer, #fadeIn)
  253.   updateDisplay(oPuppeteer)
  254.   setState(oStoryteller, #showMontage, 0)
  255.   enterNewDomain(oStoryteller, string(#Edwin), 15)
  256. end
  257.